<html>
<head><meta charset="utf-8"><title>lazy norm unused substs during HIR lowering · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20unused.20substs.20during.20HIR.20lowering.html">lazy norm unused substs during HIR lowering</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="228201520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20unused%20substs%20during%20HIR%20lowering/near/228201520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20unused.20substs.20during.20HIR.20lowering.html#228201520">(Mar 01 2021 at 09:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/lazy.20norm.20unused.20substs/near/228089919">said</a>:</p>
<blockquote>
<p>so <code>N</code> being at index <code>1</code> means that we can't just internally represent this as</p>
<p><div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">ASSOC_CT</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">ASSOC_CT</span>::<span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">todo!</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div><br>
</p>
</blockquote>
<p>during HIR lowering we could rewrite all of this to whatever we fancy, we can generate new params and re-index all of the params inside the anon const. we could then clone all where bounds on <code>foo</code> onto <code>ASSOC_CT</code>(modulo the bound containing the constant itself, if the constant is in a where bound). This may potentially duplicate a lot of where bounds, but I'd wager that in most (current) cases, there would be zero duplication, as the constants must not depend on generics at all</p>



<a name="228201836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20unused%20substs%20during%20HIR%20lowering/near/228201836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20unused.20substs.20during.20HIR.20lowering.html#228201836">(Mar 01 2021 at 09:36)</a>:</h4>
<p>we do something similar for <code>impl Trait</code> in return position, which even ends up having its own hir::Type variant: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.TyKind.html#variant.OpaqueDef">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.TyKind.html#variant.OpaqueDef</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>